package com.wsoft.system.service.impl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wsoft.core.utils.LoginUserUtil;
import com.wsoft.system.entity.SysMemberFileEntity;
import com.wsoft.system.manager.SysMemberFileManager;
import com.wsoft.system.mapper.SysMemberFileMapper;
import com.wsoft.system.query.member.file.SysMemberFileInsertQuery;
import com.wsoft.system.query.member.file.SysMemberFileListQuery;
import com.wsoft.system.query.member.file.SysMemberFileUpdateQuery;
import com.wsoft.system.service.ISysMemberFileService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author Z001
 * @Date 2025-03-06 01:28:06
 */
@Service
public class SysMemberFileServiceImpl extends ServiceImpl<SysMemberFileMapper, SysMemberFileEntity> implements ISysMemberFileService{

    @Resource
    private SysMemberFileManager sysMemberFileManager;

    /**
     * 用户个人图片-分页查询
     * @param query
     * @return PageInfo
     */
    @Override
    public PageInfo<SysMemberFileEntity> listSysMemberFile(SysMemberFileListQuery query) {
        PageHelper.startPage(query.getPageNum(), query.getPageSize());
        List<SysMemberFileEntity> list = sysMemberFileManager.list(query);
        return PageInfo.of(list);
    }

    /**
     * 用户个人图片-获取详情
     * @param id
     * @return
     */
    @Override
    public  SysMemberFileEntity getInfo(Long id) {
        return sysMemberFileManager.getById(id);
    }

    /**
     * 新增-用户个人图片
     * @param query
     * @return
     */
    @Override
    public boolean insertSysMemberFile(SysMemberFileInsertQuery query) {
        SysMemberFileEntity convert = Convert.convert(SysMemberFileEntity.class, query);
        convert.setMemberId(LoginUserUtil.getUserInfo().getLoginUserVO().getId());
        return sysMemberFileManager.save(convert);
    }

    /**
     *  更新-用户个人图片
     *
     * @param query
     * @return
     */
    @Override
    public boolean updateSysMemberFile(SysMemberFileUpdateQuery query) {
        return sysMemberFileManager.updateById(Convert.convert(SysMemberFileEntity.class, query));
    }

    /**
     * 删除-用户个人图片
     * @param id
     * @return
     */
    @Override
    public boolean delete(Long id) {
        return sysMemberFileManager.removeById(id);
    }
}
